//
//  XQueue.m
//  iSensorTest
//
//  Created by Deheng.Xu on 13-4-27.
//  Copyright (c) 2013年 Nicholas.Xu. All rights reserved.
//

#import "XQueue.h"
#import "FunctionSet.h"

@interface XQueue()
- (NSMutableArray *)__queueStacks;
@end

@implementation XQueue
@synthesize contents = __stacks;

- (id)init
{
    self = [super init];
    if (self) {
        self.maxSize = NSNotFound;
    }
    return self;
}

- (id)initWithMaxSize:(NSUInteger)maxSize
{
    self = [super init];
    if (self) {
        self.maxSize = maxSize;
    }
    return self;
}

#if !ARC_ENABLED
- (void)dealloc
{
    [__stacks release];
    [super dealloc];
}
#endif

- (void)addObject:(id)obj
{
    [self.__queueStacks addObject:obj];
    if (self.__queueStacks.count > _maxSize) {
        [self.__queueStacks removeObjectAtIndex:0];
    }
}

- (NSMutableArray *)__queueStacks
{
    if (nil == __stacks) {
        __stacks = [[NSMutableArray alloc] initWithCapacity:12];
    }
    return __stacks;
}

@end
